package com.zxk.version1.consumer;


import com.zxk.version1.core.User;

import java.io.*;
import java.net.Socket;
import java.util.Random;

/**
 * @author 朱小康
 */
public class RpcClient {
    public static void main(String[] args) {
        //建立socket链接
        try {
            Socket socket = new Socket("127.0.0.1",8081);
            InputStream inputStream = socket.getInputStream();
            OutputStream outputStream = socket.getOutputStream();
            ObjectOutputStream objectOutputStream = new ObjectOutputStream(outputStream);
            ObjectInputStream objectInputStream = new ObjectInputStream(inputStream);

            objectOutputStream.writeInt(new Random().nextInt());
            objectOutputStream.flush();
            User user = (User) objectInputStream.readObject();
            System.out.println("服务端返回user信息"+user.toString());

        } catch (IOException | ClassNotFoundException e) {
            e.printStackTrace();
            System.out.println("出现异常");
        }
    }
}
